#pragma once

#include <type_traits>
#include "../base/types.h"

OPEN_JLIB_NS


struct SUM {


  template<typename T>
  inline static auto update (const T *src, uwl src_size, typename std::make_unsigned<T>::type init = 0) noexcept -> typename std::make_unsigned<T>::type {
    auto a = init;
    for (auto sp = src, ep = sp + src_size; sp < ep; ++sp)
      a ^= *sp;
    return a;
  }


  template<typename T>
  inline static auto checksum (const T *src, uwl src_size) noexcept -> typename std::make_unsigned<T>::type {
    return update(src, src_size, 0);
  }

};


CLOSE_JLIB_NS